@echo off

REM Create build and dist directories if they don't exist
if not exist build mkdir build
if not exist dist mkdir dist

REM Generate EXE file using PyInstaller
echo Step 1: Generating executable file with PyInstaller...
pyinstaller exam_system_new.spec

IF %ERRORLEVEL% NEQ 0 (
    echo PyInstaller build failed!
    pause
    exit /b 1
)

echo Step 1 completed successfully!

REM Create Windows installer with Inno Setup
echo Step 2: Creating Windows installer with Inno Setup...

REM Check if Inno Setup exists at the specified path
IF EXIST "D:\Program_Files\Inno Setup 6\iscc.exe" (
    echo Found Inno Setup compiler, compiling installer...
    "D:\Program_Files\Inno Setup 6\iscc.exe" create_installer.iss
    
    IF %ERRORLEVEL% NEQ 0 (
        echo Inno Setup compilation failed!
        pause
        exit /b 1
    )
    
    echo Step 2 completed successfully!
    echo Installation package created in Output directory.
) ELSE (
    echo ERROR: Inno Setup compiler not found at D:\Program_Files\Inno Setup 6\iscc.exe
    echo Please verify the installation path or download from https://jrsoftware.org/isinfo.php
    pause
    exit /b 1
)

pause